package com.chhh.cranelease.controller;

import com.chhh.cranelease.entity.CarLog;
import com.chhh.cranelease.model.ResponseCode;
import com.chhh.cranelease.service.CarLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;

@RestController
@RequestMapping("carlogs/")
public class CarLogUserController {
    @Autowired
    private CarLogService service;
    @RequestMapping("insertCarLog")
    public ResponseCode insertCarLog(CarLog carLog){
        ResponseCode responseData=new ResponseCode();
        Integer count=service.insertCarLog(carLog);
        responseData.setErrorCode(0);
        responseData.setStatus("成功添加"+count+"条行车记录！");
        return responseData;
    }
    @RequestMapping("selectAll")
    public List<CarLog> selectAll(String username){
        List<CarLog> list=service.selectAll(username);
        return list;
    }
    @RequestMapping("selectById")
    public ResponseCode selectById(Integer id){
        ResponseCode responseData = new ResponseCode();
        CarLog carLog = service.selectById(id);
        responseData.setErrorCode(0);
        responseData.setStatus("success");
        responseData.setObject(carLog);
        return responseData;
    }
    @RequestMapping("updateLog")
    public ResponseCode updateLog(CarLog carLog){
        ResponseCode responseData = new ResponseCode();
        Integer count=service.updateLog(carLog);
        responseData.setErrorCode(0);
        responseData.setStatus("success");
        return responseData;
    }
    @RequestMapping("cancelLog")
    public ResponseCode cancelLog(CarLog carLog){
        ResponseCode responseData = new ResponseCode();
        Integer count=service.cancelLog(carLog);
        responseData.setErrorCode(0);
        responseData.setStatus("success");
        return responseData;
    }

}
